package com.sn.author.controller;

import com.sn.author.common.annotation.Advice;
import com.sn.author.domain.BaseResult;
import com.sn.author.domain.dto.TaskBasisInfo;
import com.sn.author.domain.taskEntity.TaskProcess;
import com.sn.author.domain.vo.TaskVo;
import com.sn.author.domain.vo.TaskParamVo;
import com.sn.author.service.dao.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2020/9/21 19:45
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/task")
@Api(tags = "任务中心")
public class TaskController {

    private final TaskService taskService;

    public TaskController(TaskService taskService) {
        this.taskService = taskService;
    }

    @PostMapping(value = "/getTaskProcessMessage")
    @ApiOperation("获取任务进度")
    public BaseResult<TaskProcess> getTaskProcessMessage(@RequestBody @Valid TaskBasisInfo taskInfo){
        return BaseResult.success(taskService.getProcessMessage(taskInfo.getTaskId(),taskInfo.getType()));
    }

    @PostMapping("/start")
    @ApiOperation("开始任务")
    public BaseResult<TaskBasisInfo> startAttention(@RequestBody @Valid TaskVo taskVo){
        return BaseResult.success(taskService.start(taskVo));
    }

    @PostMapping("/stop")
    @ApiOperation("停止任务")
    public BaseResult<Boolean> pauseAttention(@RequestBody @Valid TaskParamVo taskParamVo){
        return BaseResult.success(taskService.stop(taskParamVo.getTaskId(), taskParamVo.getTaskType()));
    }


}
